local qiaoyuan = fk.CreateSkill {
    name = "SP_heg__qiaoyuan",
}

Fk:loadTranslationTable {
    ["SP_heg__qiaoyuan"] = "樵缘",
    [":SP_heg__qiaoyuan"] = "当你明置此武将牌后，你可以令一名角色摸两张牌，然后若你的武将牌均明置，其可以弃置两张牌并令你暗置此武将牌。",

    ["#SP_heg__qiaoyuan"] = "樵缘：令一名角色摸两张牌",
    ["#SP_heg__qiaoyuan_discard"] = "樵缘：你可以弃置两张牌并暗置夏侯氏",

    ["$SP_heg__qiaoyuan1"] = "轻舒细颜，与君相敬如宾。",
    ["$SP_heg__qiaoyuan2"] = "清梦梨花，未料柴荆结缘。",
}

local H = require "packages.ol_hegemony.util"

qiaoyuan:addEffect(fk.GeneralRevealed, {
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        if target ~= player or not player:hasSkill(qiaoyuan.name) then return false end
        for _, v in pairs(data) do
            if table.contains(Fk.generals[v]:getSkillNameList(), qiaoyuan.name) then
                return true
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = room.alive_players
        local to = room:askToChoosePlayers(player, {
            min_num = 1,
            max_num = 1,
            targets = targets,
            prompt = "#SP_heg__qiaoyuan",
            skill_name = qiaoyuan.name,
            cancelable = true,
        })
        if #to > 0 then
            event:setCostData(self, { tos = to })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = event:getCostData(self).tos[1]
        to:drawCards(2, qiaoyuan.name)
        if H.allGeneralsRevealed(player) then
            local cards = room:askToCards(to, {
                min_num = 2,
                max_num = 2,
                pattern = ".",
                skill_name = qiaoyuan.name,
                include_equip = true,
                prompt = "#SP_heg__qiaoyuan_discard",
                cancelable = true,
            })
            if #cards > 0 then
                room:moveCardTo(cards, Player.Discard, to, fk.ReasonJustMove, qiaoyuan.name, nil, true, to)
                H.hideBySkillName(player, qiaoyuan.name)
            end
        end
    end,
})

return qiaoyuan
